package com.pxxy.springboot.controller;

import com.pxxy.springboot.webcase.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;
import java.util.List;

/******************
 * @Author yejf
 * @Description TODO
 */
@Controller
public class ThymeleafController {

    private static final Logger log = LoggerFactory.getLogger(ThymeleafController.class);

    @RequestMapping("/demo1")
    public String helloThymeleaf(Model model) {
        //
        log.debug("--进入了Thyemeleaf的 helloThymeleaf方法...");
        //绑定数据前端页面
        model.addAttribute("message","今天天气不错!");
        //模拟 一组用户
        User u1 = new User();
        u1.setId(1);
        u1.setUserName("admin");
        u1.setMobilePhone("13655443322");

        User u2 = new User();
        u2.setId(10);
        u2.setUserName("jack");
        u2.setMobilePhone("18977665533");

        User u3 = new User();
        u3.setId(12);
        u3.setUserName("ann");
        u3.setMobilePhone("18922336677");
        //添加到集合
        final List<User> users = Arrays.asList(u1, u2, u3);
        //
        model.addAttribute("users", users);
        //
        return "demo1";  //默认会跳到：templates/demo1.html
    }
}
